package com.iqiao.platform.service.impl;

import com.iqiao.common.exception.ResetException;
import com.iqiao.common.web.result.ReturnCode;
import com.iqiao.platform.dao.UserDao;
import com.iqiao.platform.model.User;
import com.iqiao.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by flt on 2017/11/13.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    @Transactional
    public Long save(User user) {
        // 检验用户名是否已经存在
        boolean isExist = userDao.existByUsername(user.getUsername());
        if (isExist) {
            throw new ResetException(ReturnCode.USER_USERNAME_PASSWORD_ERROR, "用户名已存在！");
        }
        userDao.save(user);
        return user.getId();
    }
}
